$(function () {
  function padZero(n) {
    if (n < 10) {
      return "0" + n;
    } else {
      return n;
    }
  }
  template.defaults.imports.dateFormat = function (cc) {
    var dt = new Date(cc);

    var y = dt.getFullYear();
    var m = padZero(dt.getMonth() + 1);
    var d = padZero(dt.getDate());

    var hh = padZero(dt.getHours());
    var mm = padZero(dt.getMinutes());
    var ss = padZero(dt.getSeconds());
    return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
  };
  /*  template.defaults.imports.dateFormat = function (cc) {
    var dt = new Date(cc); 

    var y = dt.getFullYear();
    var m = dt.getMonth() + 1;
    var d = dt.getDate().toString().padStart(2,'0');

    var hh = dt.getHours();
    var mm = pdt.getMinutes();
    var ss = dt.getSeconds();
    return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
  }; */
  function getList() {
    $.get("http://www.liulongbin.top:3006/api/news", function (res) {
      if (res.status !== 200) {
        return alert("s");
      }
      console.log(res);
      /* for (var i = 0; i < res.data.length; i++) {
        res.data[i].tags = res.data[i].tags.split(',');
      } */
      res.data.forEach((item) => {
        item.tags = item.tags.split(",");
      });
      var str = template("tpl-news", res);
      $("#news-list").html(str);
    });
  }
  getList();
});
